import request from '../utils/request'
// 获取支出类型
export const FinInfoGet = () => {
    return request.get('classes/financial', {
        params: {
            where: {
                inOrexpen: '支出'
            }
        }
    })
}

//获取支出数据
interface SearchType {
    [key: string]: string | {}
}
export const ExpenGet = (page: number = 1, limit: number = 10, search = {} as SearchType) => {
    for (let i in search) {
        if (search[i] == '') {
            delete search[i];
        }
    }
    let skip = (page - 1) * limit
    return request.get('classes/expenditure', { 
        params: {
            limit,
            skip,
            count: 1,
            where: {
                ...search,
                isExpen: '支出'
            }
        }
    })
}


// 修改支出状态

// 单个审核
export const StateUpdate = (id: string, agr: { state: string, audit: string }) => {
    return request.put('classes/expenditure/' + id, agr)
}


// 批量审核
export const StateBatch = (arr: string[], body: { state: string, audit: string }) => {
    let requests = arr.map(item => ({
        method: 'PUT',
        path: `/1.1/classes/expenditure/${item}`,
        body
    }))
    return request.post('batch', { requests })
}



// 获取收入类型
export const IncomeGet = () => {
    return request.get('classes/financial', {
        params: {
            where: {
                inOrexpen: '收入'
            }
        }
    })
}


// 获取收入列表
export const StuIncomeGet = () => {
    return request.get('classes/expenditure', {
        params: {
            where: {
                isExpen: '收入'
            }
        }
    })
}


// 获取收入数据
export const IncomeDataGet = (page: number = 1, limit: number = 10, search = {} as SearchType) => {
    for (let i in search) {
        if (search[i] == '') {
            delete search[i];
        }
    }
    let skip = (page - 1) * limit
    return request.get('classes/expenditure', {
        params: {
            limit,
            skip,
            count: 1,
            where: {
                ...search,
                isExpen: '收入'
            }
        }
    })
}